
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.SensorPortListener;
import lejos.nxt.TouchSensor;
import lejos.nxt.comm.RConsole;
import lejos.robotics.subsumption.Behavior;


public class HitWall extends RobotMoving implements Behavior, SensorPortListener {

	public TouchSensor bumper = new TouchSensor(SensorPort.S1);
	private boolean hasCollided;

	public HitWall() {
		hasCollided = false;
		SensorPort.S1.addSensorPortListener(this);
	}

	public boolean takeControl() {

		if(hasCollided) {
			return true;
		}
		return false;
	}
	
	public void suppress() {
		// How to suppress this behavior?
		RConsole.println("Suppress Hit Wall.");
		if (pilot.isMoving()) {
			pilot.stop();
		}
	}
	
	public void action() {
		RConsole.println("Hit Wall Run Action.");
		pilot.travel(-4);
		pilot.rotate(-60);
		pilot.travel(2);
		hasCollided = false;
	}

	@Override
	public void stateChanged(SensorPort arg0, int arg1, int arg2) {
		if(bumper.isPressed()) {
			hasCollided = true;
		}
	}
}
